package com.crm.controller;

import com.crm.commons.domain.ResponseData;
import com.crm.entity.CrmActivity;
import com.crm.entity.CrmClue;
import com.crm.service.ICrmClueService;
import com.crm.vo.Clue;
import com.crm.vo.ClueDetail;
import com.crm.vo.PageBean;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author junxian,dou
 * @since 2024-11-25
 */
@RestController
@RequestMapping("/crmClue")
public class CrmClueController extends BaseController {

    @Resource
    private ICrmClueService clueService;

    @ApiOperation(value = "保存线索数据")
    @PostMapping("/saveCreateClue")
    @PreAuthorize("hasAuthority('clue:add')")
    public ResponseData saveCreateClue(@RequestBody Clue clue) {
        clueService.saveCreateClue(clue);
        return  ResponseData.success();
    }

    @ApiOperation(value = "初始化线索下拉数据")
    @GetMapping("/initClueOptions")
    public ResponseData initClueOptions(){
        return ResponseData.success(clueService.initClueOptions());
    }

    /**
     * 分页查询线索
     *
     * @return
     */
    @ApiOperation(value = "查询线索列表")
    @PostMapping("/pageList")
    @PreAuthorize("hasAuthority('clue:list')")
//    @PreAuthorize("hasAuthority('activity:info')")
    public ResponseData pageList(@RequestBody PageBean pageBean) {
        PageBean<CrmClue> list = clueService.pageList(pageBean);
        return ResponseData.success(list);
    }


    @ApiOperation(value = "查询线索详情")
    @GetMapping("/getClueInfo/{id}")
    @PreAuthorize("hasAuthority('clue:info')")
    public ResponseData getClueInfo(@PathVariable String id) {
        CrmClue clue = clueService.getClueInfo(id);
        return ResponseData.success(clue);
    }


    @ApiOperation(value = "更新线索")
    @PostMapping("/update")
    @PreAuthorize("hasAuthority('clue:update')")
    public ResponseData updateClue(@RequestBody Clue clue) {
        clueService.updateClue(clue);
        return ResponseData.success();
    }

    @ApiOperation(value = "删除线索")
    @PostMapping("/deleteClue")
    @PreAuthorize("hasAuthority('clue:delete')")
    public ResponseData deleteClue(@RequestBody String[] id) {
        clueService.deleteClue(id);
        return ResponseData.success();
    }


    @ApiOperation(value = "线索详情&线索评论&线索关联活动")
    @GetMapping("/getClueDeatil/{id}")
    @PreAuthorize("hasAuthority('clue:detail')")
    public ResponseData getClueDeatil(@PathVariable String id) {
       ClueDetail clueDetail =  clueService.getClueDeatil(id);
        return ResponseData.success(clueDetail);
    }


    @ApiOperation(value = "线索详情&线索评论&线索关联活动")
    @GetMapping("/getClueinfo/{id}")
    @PreAuthorize("hasAuthority('clue:detail')")
    public ResponseData getClueinfo(@PathVariable String id) {
        Clue clue =  clueService.getClueinfo(id);
        return ResponseData.success(clue);
    }








}
